<template>
    <div>
        <a-modal
        :dialog-style="{ top: '20px' }"
         v-model:visible="visible" 
         :title="formState.id?(formState.view?'查看':'编辑'):'新增'" 
         @ok="handleOk" 
         @cancel="visible = false"
         class="enterprise-add-edit-modal-10"
         :width="1000"
         :footer="null"
        >
            <div v-if="visible">
                <a-form :form="form" layout="horizontal" class="form-descriptions-content-box">
                    <a-descriptions :column="3" bordered >
                        <a-descriptions-item >
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                设备名称
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input
                                v-model:value="formState.fsbmc"
                                placeholder="请输入设备名称"
                                v-decorator="[
                                    'fsbmc', { initialValue:formState.fsbmc, rules: rules.fsbmc}
                                ]"/>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item >
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                设备编号
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input
                                v-model:value="formState.fccbh"
                                placeholder="请输入设备编号"
                                v-decorator="[
                                    'fccbh', { initialValue:formState.fccbh, rules: rules.fccbh}
                                ]"/>
                            </a-form-item>
                        </a-descriptions-item>
                        
                        <a-descriptions-item >
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                设备型号
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入设备型号"
                                    v-model:value="formState.fsbxh"
                                    v-decorator="[
                                    'fsbxh', { initialValue:formState.fsbxh, rules: rules.fsbxh}
                                    ]"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                生产厂家
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入生产厂商"
                                    v-model:value="formState.fycd"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item v-if="formState.fsblx == '检验设备'" :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                对应场所
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入对应场所"
                                    v-model:value="formState.fdycj"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                关键技术参数
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入关键技术参数"
                                    v-model:value="formState.fsbjd"
                                    v-decorator="[
                                    'fsbjd', { initialValue:formState.fsbjd, rules: rules.fsbjd}
                                    ]"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        
                        <a-descriptions-item :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                对应品种
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入对应品种"
                                    v-model:value="formState.fsbyt"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item v-if="formState.fsblx == '生产设备'" :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                对应车间
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入对应车间"
                                    v-model:value="formState.fdycj"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item v-if="formState.fsblx == '生产设备'" :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                生产线
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入生产线"
                                    v-model:value="formState.fscx"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item v-if="formState.fsblx == '生产设备'" :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                生产能力或产量范围
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入生产能力或产量范围"
                                    v-model:value="formState.fjcfw"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item :span="3">
                            <span slot="label" class="descriptions-label-slot">
                                检定或校准情况
                            </span>
                            <a-form-item class="zm-form-model">
                                <a-input 
                                    placeholder="请输入检定或校准情况"
                                    v-model:value="formState.fjdhjzqk"
                                ></a-input>
                            </a-form-item>
                        </a-descriptions-item>
                    </a-descriptions>
                </a-form>
            </div>
            <div style="
                display: flex; justify-content: flex-end;
                margin-top: 20px; width: 100%;
                background-color: #fff;">
                <a-button @click="visible = false">取消</a-button>
                <a-button v-if="!formState.view" style="margin: 0 20px;" class="blue-btn" type="primary" @click="handleOk(true)">保存</a-button>
                <a-button v-if="!formState.view" class="blue-btn" type="primary" @click="handleOk(false)">保存并关闭</a-button>
            </div>
        </a-modal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector.vue'
import moment from 'moment'
export default {
    components:{
        compSelector,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            formState:{},
            form: this.$form.createForm(this, { name: 'coordinated' }),
            rules:{
                fccbh: [{
                    required: true,
                    message: '请输入设备编号',
                    trigger: 'blur',
                }],
                fsbmc: [{
                    required: true,
                    message: '请输入设备名称',
                    trigger: 'blur',
                }],
                // fsbjd: [{
                //     required: true,
                //     message: '请输入设备精度',
                //     trigger: 'blur',
                // }],
                // fsblx: [{
                //     required: true,
                //     message: '请选择设备类型',
                //     trigger: 'blur',
                // }],
                fsbxh: [{
                    required: true,
                    message: '请输入设备型号',
                    trigger: 'blur',
                }],
                // fsbsl: [{
                //     type:'number',
                //     required: true,
                //     message: '请输入设备数量',
                //     trigger: 'blur',
                // }],
                // fsbyt: [{
                //     required: true,
                //     message: '请输入设备用途',
                //     trigger: 'blur',
                // }],
                // fsbjd: [{
                //     required: true,
                //     message: '请输入关键技术参数',
                //     trigger: 'blur',
                // }],
                // fdj: [{
                //     type:'number',
                //     required: true,
                //     message: '请输入单价',
                //     trigger: 'blur',
                // }],
                // fsbscrq: [{
                //     type:'object',
                //     required: true,
                //     message: '请选择设备生产日期',
                //     trigger: 'blur',
                // }],
                // fgzrq: [{
                //     type:'object',
                //     required: true,
                //     message: '请选择购置日期',
                //     trigger: 'blur',
                // }],
                // fsynx: [{
                //     required: true,
                //     message: '请输入使用年限',
                //     trigger: 'blur',
                // }],
                // fjcfw: [{
                //     required: true,
                //     message: '请输入检测范围',
                //     trigger: 'blur',
                // }],
                // fsbzt: [{
                //     required: true,
                //     message: '请选择设备状态',
                //     trigger: 'blur',
                // }],

            },
        }
    },
    watch:{

    },
    mounted(){
    },
    methods:{
        getData(val){
            this.formState = {}
            this.formState = {...val,fsbscrq:val.fsbscrq?moment(val.fsbscrq,'YYYY-MM-DD'):'',fgzrq:val.fgzrq?moment(val.fgzrq,'YYYY-MM-DD'):''}
        },
        handleOk(val){
            this.form.validateFields((err, values) => {
                if (!err) {
                    if(this.formState.id){
                        this.$emit('editItem',{
                            ...this.formState,
                            ...values,
                            fsbscrq:this.formState.fsbscrq?moment(this.formState.fsbscrq).format('YYYY-MM-DD'):'',
                            fgzrq:this.formState.fgzrq?moment(this.formState.fgzrq).format('YYYY-MM-DD'):'',
                        },val)
                    }else{
                        this.$emit('addItem',{
                            ...this.formState,
                            ...values,
                            fsbscrq:this.formState.fsbscrq?moment(this.formState.fsbscrq).format('YYYY-MM-DD'):'',
                            fgzrq:this.formState.fgzrq?moment(this.formState.fgzrq).format('YYYY-MM-DD'):'',
                        },val)
                    }
                    
                }
            })
        },
    }
}
</script>
<style lang="less">
.enterprise-add-edit-modal-10{
    .add-edit-form{
        display: flex;
        flex-wrap: wrap;
        .ant-form-item{
            display: flex;
            margin-bottom: 8px;
        }
        .ant-form-item-label{
            width: 110px;
        }
        .ant-form-item-control-wrapper{
            width: 100%;
        }
        .flex-1-box{
            width: 100%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
        .flex-05-box{
            width: 50%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
    }
}
</style>